package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.IGreetingCardsRecordService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.GreetingCardsRecordCreateValidate;
import com.mdd.admin.validate.GreetingCardsRecordUpdateValidate;
import com.mdd.admin.validate.GreetingCardsRecordSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.GreetingCardsRecordListedVo;
import com.mdd.admin.vo.GreetingCardsRecordDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/cardRecord")
@Api(tags = "赠送贺卡记录管理")
public class GreetingCardsRecordController {

    @Resource
    IGreetingCardsRecordService iGreetingCardsRecordService;

    @GetMapping("/list")
    @ApiOperation(value="赠送贺卡记录列表")
    public AjaxResult<PageResult<GreetingCardsRecordListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated GreetingCardsRecordSearchValidate searchValidate) {
        PageResult<GreetingCardsRecordListedVo> list = iGreetingCardsRecordService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="赠送贺卡记录详情")
    public AjaxResult<GreetingCardsRecordDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        GreetingCardsRecordDetailVo detail = iGreetingCardsRecordService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "赠送贺卡记录新增")
    @PostMapping("/add")
    @ApiOperation(value="赠送贺卡记录新增")
    public AjaxResult<Object> add(@Validated @RequestBody GreetingCardsRecordCreateValidate createValidate) {
        iGreetingCardsRecordService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "赠送贺卡记录编辑")
    @PostMapping("/edit")
    @ApiOperation(value="赠送贺卡记录编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody GreetingCardsRecordUpdateValidate updateValidate) {
        iGreetingCardsRecordService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "赠送贺卡记录删除")
    @PostMapping("/del")
    @ApiOperation(value="赠送贺卡记录删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iGreetingCardsRecordService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
